package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.QualityTraceabilityDao;
import com.tac.pojo.mes.QualityTraceability;
import com.tac.service.mes.QualityTraceabilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QualityTraceabilityServiceImpl implements QualityTraceabilityService {


    @Autowired
    private QualityTraceabilityDao qualityTraceabilityDao;


    //质量追溯查看
    public Result<PageInfo<QualityTraceability>> getList(Integer pageNum, Integer pageSize, String serialNumber, String completionNumber, String planNumber, String jobName, String productName
            , String inspectionBatch, Date productionDateStart, Date productionDateEnd, String inspectionItem, String inspectionResult, String inspector,
                          Date inspectionTimeStart, Date inspectionTimeEnd){
        PageHelper.startPage(pageNum,pageSize);
        List<QualityTraceability> list = qualityTraceabilityDao.getList(serialNumber, completionNumber, planNumber, jobName, productName, inspectionBatch, productionDateStart
                , productionDateEnd, inspectionItem, inspectionResult, inspector, inspectionTimeStart, inspectionTimeEnd);
        PageInfo<QualityTraceability> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }
    //质量追溯删除
    public Result remove(List<Integer> ids){
        Integer integer = qualityTraceabilityDao.remove(ids);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("质量追溯删除失败");
    }
    //质量追溯修改
    public Result update(QualityTraceability qualityTraceability){
        Integer integer = qualityTraceabilityDao.update(qualityTraceability);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("质量追溯修改失败");
    }
    //质量追溯添加
    public Result save(QualityTraceability qualityTraceability){
        Integer integer = qualityTraceabilityDao.save(qualityTraceability);
        if(integer>0){
            return Result.success(qualityTraceability);
        }
        return Result.error("质量追溯添加失败");
    }
}
